setsockopt

setsockopt, and the corresponding getsockopt, can be used to get and set options for a socket. Use getsockopt to determine socket options. Use setsockopt to set socket options. The new value remains until it is modified again. The optval parameter points to a buffer that specifies the option value according to the option name (optname). The optlen parameter indicates the length of buffer pointed to by optval.  It is used in various ways depending on the specific option. In some cases, it is the length of the option value to be set.

Syntax

int setsockopt(
    __in SOCKET s,
    __in int level,
    __in int optname,
    __in const char *optval,
    __in int optlen
);

Parameters

s

Socket descriptor.

level

The layer of the network for which the option is targeted:

optname

Socket option based on the value of level. For detailed information on Winsock options, refer to Socket Options in the Winsock Reference (http://msdn.microsoft.com/en-us/library/ms740525(VS.85).aspx)

IMPORTANT!   Some values for the optname parameter are not supported for the RT-TCP/IP version of the getsockopt and setsockopt functions. See Winsock Compatibility Issues for details.

optval

Pointer to a buffer to where the option value is stored. Its proper length depends on the type of information being set as specified in the optname field.

optlen

Size, in bytes, of the buffer at optval.

Return Values

0 (zero) if the function succeeds, SOCKET_ERROR if the function fails

Use WSAGetLastError to retrieve a specific error code.

IntervalZero.com | Support | Give Feedback